package com.atguigu.eduservice.controller;


import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduComment;
import com.atguigu.eduservice.service.EduCommentService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;


import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 评论 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2022-10-22
 */
@RestController
@RequestMapping("/eduservice/coursecomment")
//@CrossOrigin
public class EduCommentController {

    @Autowired
    private EduCommentService commentService;

    //1.分页根据课程id查询课程评论的方法
    @GetMapping("getCourseRemark/{page}/{limit}/{courseId}")
    public R getCourseRemark(@PathVariable long page, @PathVariable long limit, @PathVariable String courseId){
        Page<EduComment> pageParam=new Page<>(page,limit);
        Map<String,Object> map = commentService.getCourseRemark(pageParam,courseId);
        return R.ok().data(map);
    }

    //添加评论的方法
    @PostMapping("addCourseComment")
    public R addCourseComment(@RequestBody EduComment eduComment){
        commentService.saveComment(eduComment);
        return R.ok();
    }
}

